<?php

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;

class DefaultDb_Repositories_VehicleRepository extends EntityRepository
{

    public function getByController($controller)
    {
        $em = $this->getEntityManager();
        $query = $em->createQuery('
            SELECT v
            FROM DefaultDb_Entities_Vehicle v
            JOIN v.driver u
            WHERE 
                ( v.driver = :driver OR u.parent = :driver )
                AND v.status = :status');
        $query->setParameter('driver', $controller);
        $query->setParameter('status', DefaultDb_Entities_Vehicle::STATUS_ACTIVE);
        return $query->getResult();
    }

}